' 8338-75
'GCV_FRONT = 2
'GCV_LEFT = 4
'GCV_RIGHT = 5
'GCV_EXTENDED = 7
'GCV_SIMPLIFIED = 8
'GCV_STANDARD = 9
'SIDE = GCV_FRONT

'DETAIL_LEVEL = GCV_STANDARD 'GCV_EXTENDED

hatchAngle  = 45                  
'hatchStep= 2                   

drawFace1 =1

'PAR_din=20
'PAR_d=37
'PAR_b=9
'PAR1_dain= (22+23) * 0.5
'PAR1_da= (33.5+35) * 0.5
'PAR1_dw=5
'PAR1_r = 0.5

Dim math,iDA,iPoint
Const POINT_ARR = 2  
Const ko_MathPointParam = 14

''PAR_Simpl_AXIS = 1 
''PAR_axis = 1

'++++
SUB LINE (x1,y1,x2,y2,t) Doc.ksLineSEG x1,y1,x2,y2,t END SUB
SUB Circle (x1,y1,r,t) Doc.ksCircle x1,y1,r,t END SUB
'++++
SUB DrawBall (xtr, ytr, rads, del)
  Line  xtr-rads-del,ytr,xtr+rads+del,ytr,3
  Line  xtr,ytr+rads+del,xtr,ytr-rads-del,3
  Circle xtr,ytr,rads,1
end sub
'++++
SUB Contur (rn, rf1, rf2,rf3, rf4, b,  ky) 
 x1=rf1
 x2=rf2
 x3=b-rf3
 x4=b-rf4
 y2=(rn-rf2)*ky
 y3=(rn-rf3)*ky
  doc.ksArcByPoint x2,y2,rf2,0,y2,x2,rn*ky,-ky,1 ';  /*5*/
  line x2,rn*ky,x3,rn*ky,1
 doc.ksArcByPoint x3,y3,rf3,x3,rn*ky,b,y3,-ky,1 ' ; /*6*/
 Line 0, y2, 0,0,1
 Line b,y3,b,0,1
END SUB
'++++
SUB Apx (rn)
  doc.ksColouring &HFE000000
Contur rn, PAR1_r, PAR1_r, PAR1_r,  PAR1_r, PAR_B, 1
Contur rn, PAR1_r, PAR1_r, PAR1_r,  PAR1_r, PAR_B, -1
doc.ksEndObj
END SUB
'++++
'++++
SUB Script_OnLoad ()

Set math = Kompas.GetMathematic2D
Set iDA = Kompas.GetDynamicArray(POINT_ARR)
Set iPoint = Kompas.GetParamStruct(ko_MathPointParam)

  ys=( PAR_din+PAR_D)*0.25
  xs=PAR_B*0.5                
   rn=PAR_D*0.5
  rv=PAR_din*0.5
  rv2=PAR1_dain*0.5
  rn2=PAR1_Da*0.5
  rsh = PAR1_Dw*0.5
  IF rv2 < (ys-0.8*rsh) THEN
    rv2 = ys-0.8*rsh 
end IF 
  IF rn2 > (ys+0.8*rsh) THEN
    rn2 = ys+0.8*rsh 
end IF 
  h = 0

APX rn

SELECT CASE DETAIL_LEVEL
      Case GCV_EXTENDED:

       DrawOutsideRing  rn, rn2, PAR_B, PAR1_r, xs, ys, rsh, 1 
       DrawBall xs, ys, rsh, 2
       DrawInsideRing  rv, rv2, PAR_B, PAR1_r, xs, ys, rsh, 1 
        IF PAR_AXIS <> 1 THEN
          line  0, rn-PAR1_r, 0, rv+PAR1_r, 1
          line  PAR_B, rn-PAR1_r, PAR_B, rv+PAR1_r, 1
        END IF 

        DrawOutsideRing  rn, rn2, PAR_B, PAR1_r, xs, ys, rsh, -1 
        DrawBall xs, -ys, PAR1_Dw*0.5,  2
        DrawInsideRing   rv, rv2, PAR_B, PAR1_r, xs, ys, rsh, -1 
        IF PAR_AXIS <> 1 THEN
          line  0, -(rn-PAR1_r), 0, -(rv+PAR1_r), 1
          line  PAR_B, -(rn-PAR1_r), PAR_B, -(rv+PAR1_r), 1
        END IF 

      case  GCV_STANDARD:
        DrawOutsideRing  rn, rn2, PAR_B, PAR1_r, xs, ys, rsh, 1 
        DrawBall xs, ys, PAR1_Dw*0.5, 2
        DrawInsideRing   rv, rv2, PAR_B, PAR1_r, xs, ys, rsh, 1 
        IF PAR_AXIS <> 1 THEN
          line  0, rn-PAR1_r, 0, rv+PAR1_r, 1
          line  PAR_B, rn-PAR1_r, PAR_B, rv+PAR1_r, 1 
        END IF 
      DrawSimple rv, rn, PAR1_r, PAR1_r, PAR1_r,  PAR1_r, PAR_B, -1
   
   CASE GCV_SIMPLIFIED:
       DrawSimple rv, rn, PAR1_r, PAR1_r, PAR1_r,  PAR1_r, PAR_B, 1
       DrawSimple rv, rn, PAR1_r, PAR1_r, PAR1_r,  PAR1_r, PAR_B, -1
END SELECT

 iDA.ksDeleteArray

END SUB  

'++++++

 SUB DrawOutsideRing  (rn, rn2,   b,   r,   xs, ys,   rads,  ky)
y3=(rn-r)*ky
 Dim  xp(2) 

iDA.ksClearArray
 math.ksIntersectLinsCir 0,rn2*ky,b,rn2*ky, xs,ys*ky,rads,iDA
 I = iDA.ksGetArrayCount
  doc.ksArcByPoint  r,y3,r,0,y3,r,rn*ky,-ky,1
  line r,rn*ky,b-r,rn*ky,1
  doc.ksArcByPoint  b-r,y3,r,b-r,rn*ky,b,y3,-ky,1

  IF  i<>0 THEN 
    iDA.ksGetArrayItem 0, iPoint
    xp(0) = iPoint.x
    IF i =1  THEN
      xp(1) = xp(0)
     Else
      iDA.ksGetArrayItem 1, iPoint
      xp(1) = iPoint.x
      IF xp(1)< xp(0)  THEN
         x = xp(0)
        xp(0) = xp(1)
        xp(1) = x
      End if 
    End if 

    Line b,rn2*ky,xp(1),rn2*ky,1
    Line xp(0),rn2*ky,0,rn2*ky,1
  
  else
    line b,rn2*ky, 0,rn2*ky,1 
  End if

   Doc.kshatch  0, hatchAngle, hatchStep, 0, 0, 0
   line 0,rn2*ky,0,y3,1
   doc.ksArcByPoint r,y3,r,0,y3,r,rn*ky,-ky,1
   line r,rn*ky,b-r,rn*ky,1
   doc.ksArcByPoint b-r,y3,r,b-r,rn*ky,b,y3,-ky,1
   line b,y3,b,rn2*ky,1
 

    IF  I<>0  THEN
      line b,rn2*ky,xp(1),rn2*ky,1
      if  i>1 THEN
        doc.ksArcByPoint xs,ys*ky,rads,xp(1),rn2*ky,xp(0),rn2*ky,ky,1
      End if 
     line xp(0),rn2*ky,0,rn2*ky,1
 
    else
      line b,rn2*ky, 0,rn2*ky,1 
    end if

 Doc.ksEndObj

 If PAR_AXIS = 1THEN
  line b,y3,b,0,1
   line 0,y3,0,0,1
   if  ky = 1 THEN
   line -2, 0, b+2, 0, 3 
 end if  
End if 
end sub

'+++++
sub DrawInsideRing ( rv, rv2, b, r, xs,ys, rads, ky ) 
 y2=(rv+r)*ky
   Dim  xp(2) 

  iDA.ksClearArray
  math.ksIntersectLinsCir 0,rv2*ky,b,rv2*ky, xs,ys*ky,rads,iDA
  I = iDA.ksGetArrayCount

  IF  I <>0 THEN  
   iDA.ksGetArrayItem 0, iPoint
   xp(0) = iPoint.x
   
    if i = 1 then
      xp(1) = xp(0)
    else 
      iDA.ksGetArrayItem 1, iPoint
      xp(1) = iPoint.x
      if( xp(1)< xp(0) ) then
         x = xp(0)
        xp(0) = xp(1)
        xp(1) = x
      end if
    end if
    line 0,rv2*ky,xp(0),rv2*ky,1
    line xp(1),rv2*ky,b,rv2*ky,1
  else
    line 0,rv2*ky,b,rv2*ky,1
end if  

  doc.ksArcByPoint b-r,y2,r,b,y2,b-r,rv*ky,-ky,1
  line b-r,rv*ky,r,rv*ky,1
  doc.ksArcByPoint r,y2,r,r,rv*ky,0,y2,-ky,1

 If PAR_AXIS = 1 THEN
    line r,rv*ky,r,0,1
   line b-r,rv*ky,b-r,0,1
 End if

  Doc.kshatch  0, hatchAngle-90, hatchStep, 0, 0, 0
    line b,rv2*ky,b,y2,1
    doc.ksArcByPoint b-r,y2,r,b,y2,b-r,rv*ky,-ky,1
    line b-r,rv*ky,r,rv*ky,1
    doc.ksArcByPoint r,y2,r,r,rv*ky,0,y2,-ky,1
    line 0,y2,0,rv2*ky,1

  IF  i <>0  THEN
     line 0,rv2*ky,xp(0),rv2*ky,1
      IF  i > 1 THEN
      doc.ksArcByPoint xs,ys*ky,rads,xp(0),rv2*ky,xp(1),rv2*ky,ky,1
      end if
      line xp(1),rv2*ky,b,rv2*ky,1

    else
      line 0,rv2*ky,b,rv2*ky,1
   end if


    Doc.ksEndObj

 end sub 

'++++++++
sub DrawSimple (rv, rn, rf1, rf2,rf3, rf4, b,  ky) 


 x1=rf1
 x2=rf2
 x3=b-rf3
 x4=b-rf4

 y1=(rv+rf1)*ky
 y2=(rn-rf2)*ky
 y3=(rn-rf3)*ky
 y4=(rv+rf4)*ky

  if  drawFace1=1 then
    line 0,y1,0,y2,1
end if

  doc.ksArcByPoint x2,y2,rf2,0,y2,x2,rn*ky,-ky,1 ';  /*5*/
  line x2,rn*ky,x3,rn*ky,1
  doc.ksArcByPoint x3,y3,rf3,x3,rn*ky,b,y3,-ky,1 ' ; /*6*/
  line b,y3,b,y4,1
doc.ksArcByPoint x4,y4,rf4,b,y4,x4,rv*ky,-ky,1 '; /*7*/
  line x4,rv*ky,x1,rv*ky,1
  doc.ksArcByPoint x1,y1,rf1,x1,rv*ky,0,y1,-ky,1 ';     /*8*/

 If PAR_Simpl_AXIS = 1 Then 
  line x1,y1,x3,y3,2
  line x2,y2,x4,y4,2
 Else  
  ''NEW 
   Line b/3,(rn+rv)*0.5*ky,2*b/3,(rn+rv)*0.5*ky,2
   Line b*0.5,((rn+rv)*0.5-b/6)*ky,b*0.5,((rn+rv)*0.5+b/6)*ky,2
   ''
 End If   
  if PAR_AXIS = 1 THEN  
    line b,0,b,y4,1
    line x1,0,x1,rv*ky,1
    line x4,0,x4,rv*ky,1
    if  drawFace1 =1 then
      line 0,y1,0,0,1
   end if
     if ky = 1  then
      line -2, 0, b+2, 0, 3
end if
  end if
end sub
'+++++++++++++++



'+++++
